<% add_decidim_page_title(t("title", scope: "decidim.meetings.admin.registrations_attendees.index")) %>
<div class="item_show__header">
  <h1 class="item_show__header-title">
    <%= t("title", scope: "decidim.meetings.admin.registrations_attendees.index") %>
    <div class="flex items-center gap-x-4 ml-auto">
      <%= link_to t("invites", scope: "decidim.meetings.admin.registrations.form"), meeting_registrations_invites_path(meeting), class: "button button__sm button__transparent-secondary #{"disabled" unless allowed_to? :read_invites, :meeting, meeting: meeting}" %>

      <% if allowed_to? :export_registrations, :meeting, meeting: meeting %>
        <div class="relative">
          <button class="exports button button__sm button__transparent-secondary button--title" data-controller="dropdown" data-target="export-dropdown">
            <%= t "actions.export", scope: "decidim.admin" %>
            <%= icon "arrow-down-s-line" %>
            <%= icon "arrow-down-s-line" %>
          </button>

          <ul class="dropdown dropdown__bottom" id="export-dropdown" aria-hidden="true">
            <% %w(CSV JSON Excel).each do |format| %>
              <li class="dropdown__item">
                <%= link_to export_meeting_registrations_path(meeting_id: meeting, format:), class: "dropdown__button" do %>
                  <%= t("decidim.admin.exports.export_as", name: t("decidim.#{current_component.manifest.name}.admin.exports.registrations"), export_format: format) %>
                <% end %>
              </li>
            <% end %>
          </ul>
        </div>
      <% end %>

      <%= link_to t("registration_form" , scope: "decidim.meetings.admin.registrations.form"), edit_meeting_registrations_form_path(meeting_id: meeting.id), class: "button button__sm button__transparent-secondary" %>
      <%= link_to t("manage_questions" , scope: "decidim.meetings.admin.registrations.form"), edit_questions_meeting_registrations_form_path(meeting_id: meeting.id), class: "button button__sm button__transparent-secondary" %>
    </div>
  </h1>
</div>

<div class="item__edit item__edit-1col">
  <div class="item__edit-form">
    <% if meeting.component.settings.registration_code_enabled %>
      <div class="card mb-4">
        <div class="card-divider">
          <h2 class="card-title">
            <%= t(".validate_registration_code") %>
          </h2>
        </div>
        <div class="card-section">
          <%= decidim_form_for(@validation_form, url: validate_registration_code_meeting_registrations_attendees_path, html: { class: "form form-defaults validate_meeting_registration_code" })  do |f| %>
            <div class="form__wrapper">
              <div class="card-section">
                <div class="row column">
                  <div>
                    <%= f.label :code %>
                  </div>
                  <%= f.text_field :code, label: false %>
                </div>
                <div class="row column">
                  <%= f.submit t(".validate"), class: "button button__sm button__transparent-secondary" %>
                </div>
              </div>
            </div>
          <% end %>
        </div>
      </div>
    <% end %>

    <div class="card" id="meeting-invites">
      <div class="table-stacked">
        <table class="table-list">
          <thead>
            <tr>
              <th><%= t("models.registration.fields.name", scope: "decidim.meetings") %></th>
              <th><%= t("models.registration.fields.email", scope: "decidim.meetings") %></th>
              <th><%= t("models.registration.fields.status", scope: "decidim.meetings") %></th>
              <th><%= t("models.registration.actions", scope: "decidim.meetings") %></th>
            </tr>
          </thead>
          <tbody>
            <% registrations.each do |registration| %>
              <% presenter = registration.presenter %>

              <tr data-id="<%= registration.id %>">
                <td data-label="<%= t("models.registration.fields.name", scope: "decidim.meetings") %>">
                  <%= presenter.name %>
                </td>
                <td data-label="<%= t("models.registration.fields.email", scope: "decidim.meetings") %>">
                  <%= presenter.email %>
                </td>
                <td class="<%= presenter.status_html_class %>" data-label="<%= t("models.registration.fields.status", scope: "decidim.meetings") %>">
                  <strong class="label <%= presenter.status_html_class %>">
                    <%= presenter.status %>
                  </strong>
                </td>
                <td class="table-list__actions" data-label="<%= t("models.registration.actions", scope: "decidim.meetings") %>">
                  <% if allowed_to? :update, :meeting, meeting: meeting %>
                    <button type="button" data-controller="dropdown" data-target="actions-meeting-registration-<%= registration.id %>" aria-label="<%= t("actions.actions_label", scope: "decidim.admin", resource: translated_attribute(meeting.title)) %>">
                      <%= icon "more-fill", class: "text-secondary" %>
                    </button>

                    <div class="inline-block relative">
                      <ul id="actions-meeting-registration-<%= registration.id %>" class="dropdown dropdown__action" aria-hidden="true">
                        <li class="dropdown__item">
                          <% if presenter.validated? %>
                            <div class="dropdown__button-disabled">
                              <%= with_tooltip t("tooltips.cannot_mark_attendee", scope: "decidim.admin") do %>
                                <%= icon "user-follow-line", class: "text-gray" %>
                                <span>
                                  <%= t("actions.mark_as_attendee", scope: "decidim.meetings") %>
                                </span>
                              <% end %>
                            </div>
                          <% else %>
                            <%= link_to mark_as_attendee_meeting_registrations_attendee_path(id: registration), method: :put, class: "dropdown__button" do %>
                              <%= icon "user-follow-line" %>
                              <%= t("actions.mark_as_attendee", scope: "decidim.meetings") %>
                            <% end %>
                          <% end %>
                        </li>
                      </ul>
                    </div>
                  <% end %>
                </td>
              </tr>
            <% end %>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
